* 3_MainSampleResults
** Goal: Generate main regression tables 
** Beatrice Lee
** Date Created: 2023-01-31 
** Last Updated: 2024-07-31 // tja
** Non-substantive updates: 2025-07-29 by Shantanu Kamat

*** load dataset ***
cd "$Data/Processing"
use state_elections_panel_df5_20240731, clear

* unhash this line to install reghdfe (used for panel regressions) and ftools (used by reghdfe)
*ssc install reghdfe
*ssc install ftools

**************************************** TABLES **************************************************

***** Summary Stats Table 

* panel a: pandemic sample
eststo clear

estpost tabstat incumbent_vote_share_top2 total_1k_muni_aid_per_resident reps_per_million norm_vote_top2_share_sd osi_march2020_rescale trump_voteshare_2016 total_deaths_endyear total_cases_endyear change_disp_inc_per_cap1k_py unemp_rate_elect_yr if (year >= 2020 & year <= 2022), c(stat) stat(mean sd min max n)

cd "$Results/"
#delimit ; 
esttab using "sumstats1_20240731.tex", replace ///
 cells("mean(fmt(3)) sd(fmt(3)) min(fmt(3)) max(fmt(3)) count(fmt(0))") /// Which Stats to Output
 nonumber /// Do not put numbers below column titles
 nomtitle /// This option mainly for regression tables
 booktabs /// Top, Mid, Bottom Rule
 noobs /// We don't need observation counts because count is N
 title("Summary Statistics\label{tab1}") /// Latex number this for us
 collabels("Mean" "SD" "Min" "Max" "N") /// Name of each column
 addnote("TKTKTK") /// Note below table
 coeflabels(incumbent_vote_share_top2 "Incumbent Vote Share" ///
            total_1k_muni_aid_per_resident "Total Aid per Resident (USD thousands)" ///
            reps_per_million "Reps per Million" ///
            norm_vote_top2_share_sd "Normal Vote" ///
            osi_march2020_rescale "March 2020 OSI" ///
            trump_voteshare_2016 "Trump Vote Share 2016" ///
            total_deaths_endyear "Total Deaths" ///
            total_cases_endyear "Total Cases" ///
            change_disp_inc_per_cap1k_py "Change Disposable Income From Previous Year (USD thousands)" ///
            unemp_rate_elect_yr "Change in Unemployment Rate From Previous Year") /// Label variables right in command

eststo clear

estpost tabstat incumbent_vote_share_top2 total_1k_muni_aid_per_resident reps_per_million norm_vote_top2_share_sd change_disp_inc_per_cap1k_py unemp_rate_elect_yr if (year >= 2013 & year <= 2019), c(stat) stat(mean sd min max n)

cd "$Results/"
#delimit ;
esttab using "sumstats2_20240731.tex", replace ///
 cells("mean(fmt(3)) sd(fmt(3)) min(fmt(3)) max(fmt(3)) count(fmt(0))") ///Which Stats to Output
 nonumber ///Do not put numbers below column titles
 nomtitle ///This option mainly for regression tables
 booktabs ///Top, Mid, Bottom Rule
 noobs ///We don't need observation counts because count is N
 title("Summary Statistics\label{tab2}") ///Latex number this for us
 collabels("Mean" "SD" "Min" "Max" "N") /// Name of each column
 addnote("TKTKTK") ///Note below table
 coeflabels(incumbent_vote_share_top2 "Incumbent Vote Share" total_1k_muni_aid_per_resident "Total Aid per Resident (USD thousands)" reps_per_million "Reps per Million" norm_vote_top2_share_sd "Normal Vote" change_disp_inc_per_cap1k_py "Change Disposable Income From Previous Year (USD thousands)" unemp_rate_elect_yr "Change in Unemployment Rate From Previous Year") ///Label variables right in command
;

***** Table 1: Baseline results
eststo clear

**** No normal vote control 
*** Reduced Form
eststo: regress incumbent_vote_share_top2 reps_per_million  if (year >= 2020 & year <= 2022), vce(cluster state) 

*** First Stage
eststo: regress total_1k_muni_aid_per_resident reps_per_million if (year >= 2020 & year <= 2022), vce(cluster state) 

*** 2SLS
eststo: ivregress 2sls incumbent_vote_share_top2 (total_1k_muni_aid_per_resident = reps_per_million) if (year >= 2020 & year <= 2022), vce(cluster state) first
estat firststage

mat fstat = r(singleresults)
estadd scalar fs = fstat[1,4] 

**** With normal vote control 
*** Reduced Form
eststo: regress incumbent_vote_share_top2 reps_per_million norm_vote_top2_share_sd  if (year >= 2020 & year <= 2022), vce(cluster state) 

*** First Stage
eststo: regress  total_1k_muni_aid_per_resident reps_per_million norm_vote_top2_share_sd if (year >= 2020 & year <= 2022), vce(cluster state) 

*** 2SLS
eststo: ivregress 2sls incumbent_vote_share_top2 norm_vote_top2_share_sd (total_1k_muni_aid_per_resident = reps_per_million ) if (year >= 2020 & year <= 2022), vce(cluster state) first
estat firststage

mat fstat = r(singleresults)
estadd scalar fs = fstat[1,4] 

****** Export T1 to Latex
cd "$Results/"
esttab using "baseline_results_20240731.tex", replace ///
 collabels("\multicolumn{1}{c}{1l}" "\multicolumn{1}{c}{l2}" "\multicolumn{1}{c}{l3}" "\multicolumn{1}{c}{l4}" "\multicolumn{1}{c}{l5}" "\multicolumn{1}{c}{l6}") ///
 b(3) se(3) nomtitle label star(* 0.10 ** 0.05 *** 0.01) ///
 stats(N r2 fs, fmt(0 3) layout("\multicolumn{1}{c}{@}" "\multicolumn{1}{c}{@}")  labels(`"Observations"' `"\(R^{2}\)"' `"\(F\)"')) drop(_cons) ///
 booktabs ///
 title("Baseline Results") ///
 addnotes("Note: TKTKTKTK")

 
***** Table 2: Probing Robustness to exposure to resource and tourism driven declines
eststo clear

*** Baseline 2SLS
eststo: ivregress 2sls incumbent_vote_share_top2 norm_vote_top2_share_sd (total_1k_muni_aid_per_resident = reps_per_million ) if (year >= 2020 & year <= 2022), vce(cluster state) first
estat firststage

mat fstat = r(singleresults)
estadd scalar fs = fstat[1,4] 

*** Baseline 2SLS without Resource Intensive States (& state != "AK" & state != "ND" & state != "WY")
eststo: ivregress 2sls incumbent_vote_share_top2 norm_vote_top2_share_sd (total_1k_muni_aid_per_resident = reps_per_million ) if (year >= 2020 & year <= 2022) & state != "AK" & state != "ND" & state != "WY", vce(cluster state) first
estat firststage

mat fstat = r(singleresults)
estadd scalar fs = fstat[1,4] 

*** Baseline 2SLS without Tourism Intensive States (& state != "HI" & state != "NV" & state != "FL")
eststo: ivregress 2sls incumbent_vote_share_top2 norm_vote_top2_share_sd (total_1k_muni_aid_per_resident = reps_per_million ) if (year >= 2020 & year <= 2022) & state != "HI" & state != "NV" & state != "FL", vce(cluster state) first
estat firststage

mat fstat = r(singleresults)
estadd scalar fs = fstat[1,4] 

*** Baseline 2SLS without Resource of Tourism Intensive States (& state != "HI" & state != "NV" & state != "FL" & state != "AK" & state != "ND" & state != "WY")
eststo: ivregress 2sls incumbent_vote_share_top2 norm_vote_top2_share_sd (total_1k_muni_aid_per_resident = reps_per_million ) if (year >= 2020 & year <= 2022) & state != "AK" & state != "ND" & state != "WY" & state != "HI" & state != "NV" & state != "FL", vce(cluster state) first
estat firststage

mat fstat = r(singleresults)
estadd scalar fs = fstat[1,4] 

****** Export T2 to Latex
cd "$Results/"
esttab using "robustness_resources_tourism_20240731.tex", replace ///
 collabels("\multicolumn{1}{c}{Baseline}" "\multicolumn{1}{c}{Without Resource Intensive States}" "\multicolumn{1}{c}{Without Tourism Intensive States}" "\multicolumn{1}{c}{Without Resource and Tourism Intensive States}") ///
 b(3) se(3) nomtitle label star(* 0.10 ** 0.05 *** 0.01) ///
 stats(N r2 fs, fmt(0 3) layout("\multicolumn{1}{c}{@}" "\multicolumn{1}{c}{@}")  labels(`"Observations"' `"\(R^{2}\)"' `"\(F\)"')) drop(_cons) ///
 booktabs ///
 title("Probing Robustness to Exposure to Resource and Tourism Driven Declines") ///
 addnotes("Note: Resource intensive states include Alaska, North Dakota, and Wyoming. Tourism intensive states include Hawaii, Nevada, and Florida.")

***** Table 3: Probing Robustness to COVID policy and "preferences" as proxied by Trump vote share
eststo clear

*** Baseline 2SLS
eststo: ivregress 2sls incumbent_vote_share_top2 norm_vote_top2_share_sd (total_1k_muni_aid_per_resident = reps_per_million ) if (year >= 2020 & year <= 2022), vce(cluster state) first
estat firststage

mat fstat = r(singleresults)
estadd scalar fs = fstat[1,4] 

*** Baseline with OSI Control
eststo: ivregress 2sls incumbent_vote_share_top2 norm_vote_top2_share_sd osi_march2020_rescale  (total_1k_muni_aid_per_resident = reps_per_million ) if (year >= 2020 & year <= 2022), vce(cluster state) first
estat firststage

mat fstat = r(singleresults)
estadd scalar fs = fstat[1,4] 

*** Baseline with Trump Control
eststo: ivregress 2sls incumbent_vote_share_top2 norm_vote_top2_share_sd trump_voteshare_2016 (total_1k_muni_aid_per_resident = reps_per_million ) if (year >= 2020 & year <= 2022), vce(cluster state) first
estat firststage

mat fstat = r(singleresults)
estadd scalar fs = fstat[1,4] 

*** Baseline with Both OSI and Trump Controls
eststo: ivregress 2sls incumbent_vote_share_top2 norm_vote_top2_share_sd osi_march2020_rescale trump_voteshare_2016 (total_1k_muni_aid_per_resident = reps_per_million ) if (year >= 2020 & year <= 2022), vce(cluster state) first
estat firststage

mat fstat = r(singleresults)
estadd scalar fs = fstat[1,4] 

****** Export T3 to Latex
cd "$Results/"
esttab using "robustness_covid_preferences_20240731.tex", replace ///
 collabels("\multicolumn{1}{c}{Baseline}" "\multicolumn{1}{c}{With OSI}" "\multicolumn{1}{c}{With Trump Vote Share}" "\multicolumn{1}{c}{With OSI and Trump Vote Share}") ///
 b(3) se(3) nomtitle label star(* 0.10 ** 0.05 *** 0.01) ///
 stats(N r2 fs, fmt(0 3) layout("\multicolumn{1}{c}{@}" "\multicolumn{1}{c}{@}")  labels(`"Observations"' `"\(R^{2}\)"' `"\(F\)"')) drop(_cons) ///
 booktabs /// 
 title("Probing Robustness to COVID Policy and Preference as Proxied by Trump Vote Share") ///
 addnotes("Note: TKTKTKTK")

***** Table 5: Placebo Check
eststo clear

**** No normal vote control
*** Reduced form
eststo: reg incumbent_vote_share_top2 reps_per_million if (year >= 2013 & year <= 2019), vce(cluster state)

*** 2SLS
eststo: ivregress 2sls incumbent_vote_share_top2 (total_1k_muni_aid_per_resident = reps_per_million) if (year >= 2013 & year <= 2019), vce(cluster state) first
estat firststage

mat fstat = r(singleresults)
estadd scalar fs = fstat[1,4] 

**** With normal vote control
*** Reduced form
eststo: reg incumbent_vote_share_top2 reps_per_million norm_vote_top2_share_sd if (year >= 2013 & year <= 2019), vce(cluster state)

*** 2SLS
eststo: ivregress 2sls incumbent_vote_share_top2 norm_vote_top2_share_sd (total_1k_muni_aid_per_resident = reps_per_million) if (year >= 2013 & year <= 2019), vce(cluster state) first
estat firststage

mat fstat = r(singleresults)
estadd scalar fs = fstat[1,4] 

****** Export T5 to Latex
cd "$Results/"
esttab using "placebo_20240731.tex", replace ///
 collabels("\multicolumn{1}{c}{Reduced Form}" "\multicolumn{1}{c}{2SLS}" "\multicolumn{1}{c}{Reduced Form}" "\multicolumn{1}{c}{2SLS}") ///
 b(3) se(3) nomtitle label star(* 0.10 ** 0.05 *** 0.01) ///
 stats(N r2 fs, fmt(0 3) layout("\multicolumn{1}{c}{@}" "\multicolumn{1}{c}{@}")  labels(`"Observations"' `"\(R^{2}\)"' `"First Stage F-Stat"')) drop(_cons) ///
 booktabs /// 
 title("Placebo Check") ///
 addnotes("Note: TKTKTKTK")

***** Table 6: Panel Regressions
eststo clear

**** Regressions including all elections from 2013 on, with 2020 included in the pandemic period
*** Simple panel regressions allowing the relationship between reps per million and the incumbent
*** vote share to vary during the pandemic

*** Col1 (no fe, no norm vote)
eststo: reg incumbent_vote_share_top2 c.reps_per_million##i.duringpandemic if year > 2012 , vce(cluster state)
estadd local office_fe "No"
estadd local year_fe "No"
estadd local state_fe "No"
estadd local norm_vote_year_fe "No"
estadd local office_state_fe "No"

*** Col2 (no fe, + normal vote)
eststo: reg incumbent_vote_share_top2 c.reps_per_million##i.duringpandemic norm_vote_top2_share_sd if year > 2012 , vce(cluster state)
estadd local office_fe "No"
estadd local year_fe "No"
estadd local state_fe "No"
estadd local norm_vote_year_fe "No"
estadd local office_state_fe "No"

*** Col3 (norm vote x year fe)
eststo: reg incumbent_vote_share_top2 c.reps_per_million##i.duringpandemic c.norm_vote_top2_share_sd##i.year if year > 2012 , vce(cluster state)
estadd local office_fe "No"
estadd local year_fe "No"
estadd local state_fe "No"
estadd local norm_vote_year_fe "Yes"
estadd local office_state_fe "No"

*** Panel regressions estimating the differential relationship between reps per million and the incumbent
*** Col4: vote share during the pandemic by including state and year fixed effects
eststo: reghdfe incumbent_vote_share_top2 c.reps_per_million##i.duringpandemic c.norm_vote_top2_share_sd#i.year if year > 2012 , vce(cluster state) a(sfips year)
estadd local office_fe "No"
estadd local year_fe "Yes"
estadd local state_fe "Yes"
estadd local norm_vote_year_fe "Yes"
estadd local office_state_fe "No"

** Col5: Adds Office Fixed Effects
eststo: reghdfe incumbent_vote_share_top2 c.reps_per_million##i.duringpandemic c.norm_vote_top2_share_sd#i.year if year > 2012 , vce(cluster state) a(sfips office_num year)
estadd local office_fe "Yes"
estadd local year_fe "Yes"
estadd local state_fe "Yes"
estadd local norm_vote_year_fe "Yes"
estadd local office_state_fe "No"

** Col6: Adds Office by State Fixed Effects
eststo: reghdfe incumbent_vote_share_top2 c.reps_per_million##i.duringpandemic c.norm_vote_top2_share_sd#i.year if year > 2012 , vce(cluster state) a(sfips#office_num year)
estadd local office_fe "Yes"
estadd local year_fe "Yes"
estadd local state_fe "Yes"
estadd local norm_vote_year_fe "Yes"
estadd local office_state_fe "Yes"

****** Export T6 to Latex
cd "$Results/"
esttab using "panel_regs_20240731.tex", replace ///
 collabels("\multicolumn{1}{c}{col1}" "\multicolumn{1}{c}{col2}" "\multicolumn{1}{c}{col3}" "\multicolumn{1}{c}{col4}" "\multicolumn{1}{c}{col5}" "\multicolumn{1}{c}{col6}") ///
 b(3) se(3) nomtitle label star(* 0.10 ** 0.05 *** 0.01) ///
 stats(N r2 office_fe year_fe state_fe norm_vote_year_fe office_state_fe, fmt(0 3) layout("\multicolumn{1}{c}{@}" "\multicolumn{1}{c}{@}")  labels(`"Observations"' `"\(R^{2}\)"' `"Office FE"' `"Year FE"' `"State FE"' `"Normal Vote x Year FE"' `"Office x State FE"')) drop(_cons) ///
 booktabs /// 
 title("Panel Regressions") ///
 addnotes("Note: TKTKTKTK")

***** Table 7: Probing potential role of COVID outcomes and economic outcomes as mechanisms
eststo clear

*** Did Aid Impact Deaths
eststo: ivregress 2sls total_deaths_endyear norm_vote_top2_share_sd (total_1k_muni_aid_per_resident = reps_per_million ) if (year >= 2020 & year <= 2022), vce(cluster state) first
estat firststage

mat fstat = r(singleresults)
estadd scalar fs = fstat[1,4] 

*** Did Aid Impact Cases
eststo: ivregress 2sls total_cases_endyear norm_vote_top2_share_sd (total_1k_muni_aid_per_resident = reps_per_million ) if (year >= 2020 & year <= 2022), vce(cluster state) first
estat firststage

mat fstat = r(singleresults)
estadd scalar fs = fstat[1,4] 

*** Did Aid Impact Disposable Income
eststo: ivregress 2sls change_disp_inc_per_cap1k_py norm_vote_top2_share_sd (total_1k_muni_aid_per_resident = reps_per_million ) if (year >= 2020 & year <= 2022), vce(cluster state) first
estat firststage

mat fstat = r(singleresults)
estadd scalar fs = fstat[1,4] 

*** Did Aid Unemployment
eststo: ivregress 2sls unemp_rate_elect_yr norm_vote_top2_share_sd (total_1k_muni_aid_per_resident = reps_per_million ) if (year >= 2020 & year <= 2022), vce(cluster state) first
estat firststage

mat fstat = r(singleresults)
estadd scalar fs = fstat[1,4] 

****** Export T7 to Latex
cd "$Results/"
esttab using "mechanisms_20240731.tex", replace ///
 collabels("\multicolumn{1}{c}{Total Deaths}" "\multicolumn{1}{c}{Total Cases}" "\multicolumn{1}{c}{Change Disp. Inc.}" "\multicolumn{1}{c}{Unemp. Rate}") ///
 b(3) se(3) nomtitle label star(* 0.10 ** 0.05 *** 0.01) ///
 stats(N r2 fs, fmt(0 3) layout("\multicolumn{1}{c}{@}" "\multicolumn{1}{c}{@}")  labels(`"Observations"' `"\(R^{2}\)"' `"First Stage F-Stat"')) drop(_cons) ///
 booktabs /// 
 title("Probing Potential Role of COVID Outcomes and Economic Outcomes As Mechanisms") ///
 addnotes("Note: TKTKTKTK")
 

***** Appendix Table A.5: Baseline results using "running" aid variable 
eststo clear

**** No normal vote control 
*** Reduced Form
eststo: regress incumbent_vote_share_top2 reps_per_million if (year >= 2020 & year <= 2022), vce(cluster state) 

*** First Stage
eststo: regress running_1k_aid_per_resident reps_per_million if (year >= 2020 & year <= 2022), vce(cluster state) 

*** 2SLS
eststo: ivregress 2sls incumbent_vote_share_top2 (running_1k_aid_per_resident = reps_per_million) if (year >= 2020 & year <= 2022), vce(cluster state) first
estat firststage

mat fstat = r(singleresults)
estadd scalar fs = fstat[1,4] 

**** With normal vote control 
*** Reduced Form
eststo: regress incumbent_vote_share_top2 reps_per_million norm_vote_top2_share_sd  if (year >= 2020 & year <= 2022), vce(cluster state) 

*** First Stage
eststo: regress  running_1k_aid_per_resident reps_per_million norm_vote_top2_share_sd if (year >= 2020 & year <= 2022), vce(cluster state) 

*** 2SLS
eststo: ivregress 2sls incumbent_vote_share_top2 norm_vote_top2_share_sd (running_1k_aid_per_resident = reps_per_million ) if (year >= 2020 & year <= 2022), vce(cluster state) first
estat firststage

mat fstat = r(singleresults)
estadd scalar fs = fstat[1,4] 

****** Export Table A.5 to Latex
cd "$Results/"
esttab using "running_aid_20240731.tex", replace ///
 collabels("\multicolumn{1}{c}{1l}" "\multicolumn{1}{c}{l2}" "\multicolumn{1}{c}{l3}" "\multicolumn{1}{c}{l4}" "\multicolumn{1}{c}{l5}" "\multicolumn{1}{c}{l6}") ///
 b(3) se(3) nomtitle label star(* 0.10 ** 0.05 *** 0.01) ///
 stats(N r2 fs, fmt(0 3) layout("\multicolumn{1}{c}{@}" "\multicolumn{1}{c}{@}")  labels(`"Observations"' `"\(R^{2}\)"' `"First Stage F-Stat"')) drop(_cons) ///
 booktabs ///
 title("Baseline Results Using Running Total of COVID-19 Aid") ///
 addnotes("Note: TKTKTKTK")
 
 ***** Appendix Table A.6: Panel Regressions for SENATE
eststo clear

**** Regressions including all elections from 2013 on, with 2020 included in the pandemic period
*** Simple panel regressions allowing the relationship between reps per million and the incumbent
*** vote share to vary during the pandemic

*** Col1
eststo: reg incumbent_vote_share_top2 c.reps_per_million##i.duringpandemic if year > 2012 & office == "senate" , vce(cluster state)
estadd local office_fe "No"
estadd local year_fe "No"
estadd local state_fe "No"
estadd local norm_vote_year_fe "No"
estadd local office_state_fe "No"

*** Col2
eststo: reg incumbent_vote_share_top2 c.reps_per_million##i.duringpandemic norm_vote_top2_share_sd if year > 2012 & office == "senate" , vce(cluster state)
estadd local office_fe "No"
estadd local year_fe "No"
estadd local state_fe "No"
estadd local norm_vote_year_fe "No"
estadd local office_state_fe "No"

*** Col3
eststo: reg incumbent_vote_share_top2 c.reps_per_million##i.duringpandemic c.norm_vote_top2_share_sd##i.year if year > 2012 & office == "senate" , vce(cluster state)
estadd local office_fe "No"
estadd local year_fe "Yes"
estadd local state_fe "No"
estadd local norm_vote_year_fe "Yes"
estadd local office_state_fe "No"

*** Panel regressions estimating the differential relationship between reps per million and the incumbent
*** Col4: vote share during the pandemic by including state and year fixed effects
eststo: reghdfe incumbent_vote_share_top2 c.reps_per_million##i.duringpandemic c.norm_vote_top2_share_sd#i.year if year > 2012 & office == "senate" , vce(cluster state) a(sfips year)
estadd local office_fe "No"
estadd local year_fe "Yes"
estadd local state_fe "Yes"
estadd local norm_vote_year_fe "Yes"
estadd local office_state_fe "No"

***** Appendix Table A.6: Panel Regressions for GUB
*eststo clear

**** Regressions including all elections from 2013 on, with 2020 included in the pandemic period
*** Simple panel regressions allowing the relationship between reps per million and the incumbent
*** vote share to vary during the pandemic

*** Col5
eststo: reg incumbent_vote_share_top2 c.reps_per_million##i.duringpandemic if year > 2012 & office == "gub" , vce(cluster state)
estadd local office_fe "No"
estadd local year_fe "No"
estadd local state_fe "No"
estadd local norm_vote_year_fe "No"
estadd local office_state_fe "No"

*** Col6
eststo: reg incumbent_vote_share_top2 c.reps_per_million##i.duringpandemic norm_vote_top2_share_sd if year > 2012 & office == "gub", vce(cluster state)
estadd local office_fe "No"
estadd local year_fe "No"
estadd local state_fe "No"
estadd local norm_vote_year_fe "No"
estadd local office_state_fe "No"

*** Col7
eststo: reg incumbent_vote_share_top2 c.reps_per_million##i.duringpandemic c.norm_vote_top2_share_sd##i.year if year > 2012 & office == "gub", vce(cluster state)
estadd local office_fe "No"
estadd local year_fe "Yes"
estadd local state_fe "No"
estadd local norm_vote_year_fe "Yes"
estadd local office_state_fe "No"

*** Panel regressions estimating the differential relationship between reps per million and the incumbent
*** Col8: vote share during the pandemic by including state and year fixed effects
eststo: reghdfe incumbent_vote_share_top2 c.reps_per_million##i.duringpandemic c.norm_vote_top2_share_sd#i.year if year > 2012 & office == "gub", vce(cluster state) a(sfips year)
estadd local office_fe "No"
estadd local year_fe "Yes"
estadd local state_fe "Yes"
estadd local norm_vote_year_fe "Yes"
estadd local office_state_fe "No"

 ****** Export Table A.6 to Latex
cd "$Results/"
esttab using "panel_regs_by_race_20240731.tex", replace ///
 collabels("\multicolumn{1}{c}{col1}" "\multicolumn{1}{c}{col2}" "\multicolumn{1}{c}{col3}" "\multicolumn{1}{c}{col4}" "\multicolumn{1}{c}{col5}" "\multicolumn{1}{c}{col6}" "\multicolumn{1}{c}{col7}" "\multicolumn{1}{c}{col8}") ///
 b(3) se(3) nomtitle label star(* 0.10 ** 0.05 *** 0.01) ///
 stats(N r2 office_fe year_fe state_fe norm_vote_year_fe office_state_fe, fmt(0 3) layout("\multicolumn{1}{c}{@}" "\multicolumn{1}{c}{@}")  labels(`"Observations"' `"\(R^{2}\)"' `"Office FE"' `"Year FE"' `"State FE"' `"Normal Vote x Year FE"' `"Office x State FE"')) drop(_cons) ///
 booktabs /// 
 title("Panel Regressions By Office") ///
 addnotes("Note: TKTKTKTK")

  ** Test of significance between senate & governor races
** For each, run on full sample between 2013-2022 EXCLUDING house races
* specification 1
reg incumbent_vote_share_top2 c.reps_per_million##i.duringpandemic##i.gub_ind if year > 2012 & office != "house" , vce(cluster state)

* specification 2
reg incumbent_vote_share_top2 c.reps_per_million##i.duringpandemic##i.gub_ind c.norm_vote_top2_share_sd##i.gub_ind if year > 2012 & office != "house", vce(cluster state)

* specification 3
reg incumbent_vote_share_top2 c.reps_per_million##i.duringpandemic##i.gub_ind c.norm_vote_top2_share_sd##i.year##i.gub_ind if year > 2012 & office != "house", vce(cluster state)

* specification 4 v1
reghdfe incumbent_vote_share_top2 c.reps_per_million##i.duringpandemic##i.gub_ind c.norm_vote_top2_share_sd##i.year##i.gub_ind if year > 2012 & office != "house", vce(cluster state) a(sfips year)
 
di  2.649884 + 3.062427 /*sums to 5.712311 - about 0.1 less than the equivalent gub coefficient*/

* specification 4 v2 - try single # interaction for the second term?
reghdfe incumbent_vote_share_top2 c.reps_per_million##i.duringpandemic##i.gub_ind c.norm_vote_top2_share_sd#i.year#i.gub_ind if year > 2012 & office != "house", vce(cluster state) a(sfips year)

di  2.656366 + 2.890761 /*sum to 5.547127 - about 0.3 less than the equivalent gub coeff*/
 
* specification 4 v2 - try double ## interaction for gub inc, single # for year?
reghdfe incumbent_vote_share_top2 c.reps_per_million##i.duringpandemic##i.gub_ind c.norm_vote_top2_share_sd#i.year##i.gub_ind if year > 2012 & office != "house", vce(cluster state) a(sfips year)

di  2.656366  + 2.890761 /*sum to 5.547127 - same as before*/

* original model 4 (for comparison): 
reghdfe incumbent_vote_share_top2 c.reps_per_million##i.duringpandemic c.norm_vote_top2_share_sd#i.year if year > 2012 & office == "senate" , vce(cluster state) a(sfips year) 

/*in original model 4, coeff on pandemic x reps = 2.850459 (compared to 2.649884 in the model testing for significance))*/

***** Table 4: Population Density regressions

eststo clear

*** Baseline 2SLS
eststo: ivregress 2sls incumbent_vote_share_top2 norm_vote_top2_share_sd (total_1k_muni_aid_per_resident = reps_per_million ) if (year >= 2020 & year <= 2022), vce(cluster state) first
estat firststage

mat fstat = r(singleresults)
estadd scalar fs = fstat[1,4] 

*** Baseline + pop density
eststo: ivregress 2sls incumbent_vote_share_top2 norm_vote_top2_share_sd pple_per_sq_mile (total_1k_muni_aid_per_resident = reps_per_million ) if (year >= 2020 & year <= 2022), vce(cluster state) first
estat firststage

mat fstat = r(singleresults)
estadd scalar fs = fstat[1,4] 

*** Baseline + pop
eststo: ivregress 2sls incumbent_vote_share_top2 norm_vote_top2_share_sd pop_1M (total_1k_muni_aid_per_resident = reps_per_million ) if (year >= 2020 & year <= 2022), vce(cluster state) first
estat firststage

mat fstat = r(singleresults)
estadd scalar fs = fstat[1,4] 

*** Baseline + total area per square mile
eststo: ivregress 2sls incumbent_vote_share_top2 norm_vote_top2_share_sd total_area_10k_sq_mile (total_1k_muni_aid_per_resident = reps_per_million ) if (year >= 2020 & year <= 2022), vce(cluster state) first
estat firststage

mat fstat = r(singleresults)
estadd scalar fs = fstat[1,4] 

*** Baseline + pple_per_sq_mile + year_specific_pop + total_area_sq_mile
eststo: ivregress 2sls incumbent_vote_share_top2 norm_vote_top2_share_sd total_area_10k_sq_mile pple_per_sq_mile pop_1M (total_1k_muni_aid_per_resident = reps_per_million ) if (year >= 2020 & year <= 2022), vce(cluster state) first
estat firststage

mat fstat = r(singleresults)
estadd scalar fs = fstat[1,4] 

****** Export T4 to Latex
cd "$Results/"
esttab using "pop_density_20240731.tex", replace ///
 collabels("\multicolumn{1}{c}{Baseline}" "\multicolumn{1}{c}{With Population Density}" "\multicolumn{1}{c}{With Population}" "\multicolumn{1}{c}{With Total Area}" "\multicolumn{1}{c}{With Total Area}") ///
 b(3) se(3) nomtitle label star(* 0.10 ** 0.05 *** 0.01) ///
 stats(N r2 fs, fmt(0 3) layout("\multicolumn{1}{c}{@}" "\multicolumn{1}{c}{@}")  labels(`"Observations"' `"\(R^{2}\)"' `"\(F\)"')) drop(_cons) ///
 booktabs /// 
 title("Probing Robustness to Population Density Measures") ///
 addnotes("Note: TKTKTKTK")



